.class public Lcom/glympse/platform/common/UploadAvatarJob;
.super Lcom/glympse/platform/common/HttpJob;
.source "UploadAvatarJob.java"

# interfaces
.implements Lcom/glympse/platform/common/GlympseListener;


# instance fields
.field private m_abAfter:[B

.field private m_abBefore:[B

.field private m_abImage:[B

.field private m_nRotation:I

.field private m_oImage:Lcom/glympse/platform/GImage;

.field private m_strAgent:Ljava/lang/String;

.field private m_strSession:Ljava/lang/String;


# direct methods
.method public constructor <init>(Lcom/glympse/platform/GImage;I)V
    .locals 3
    .parameter "oImage"
    .parameter "nRotation"

    .prologue
    const/4 v2, 0x1

    const/4 v1, 0x0

    .line 33
    invoke-direct {p0}, Lcom/glympse/platform/common/HttpJob;-><init>()V

    .line 23
    invoke-static {}, Lcom/glympse/platform/Platform;->instance()Lcom/glympse/platform/Platform;

    move-result-object v0

    invoke-virtual {v0}, Lcom/glympse/platform/Platform;->GetBrowserAgent()Ljava/lang/String;

    move-result-object v0

    iput-object v0, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_strAgent:Ljava/lang/String;

    .line 24
    invoke-static {}, Lcom/glympse/platform/Platform;->instance()Lcom/glympse/platform/Platform;

    move-result-object v0

    iget-object v0, v0, Lcom/glympse/platform/Platform;->m_oServerPost:Lcom/glympse/platform/common/ServerPost;

    iget-object v0, v0, Lcom/glympse/platform/common/ServerPost;->m_strSession:Ljava/lang/String;

    iput-object v0, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_strSession:Ljava/lang/String;

    .line 25
    iput-object v1, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_oImage:Lcom/glympse/platform/GImage;

    .line 26
    const/4 v0, 0x0

    iput v0, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_nRotation:I

    .line 28
    iput-object v1, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_abBefore:[B

    .line 29
    iput-object v1, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_abAfter:[B

    .line 30
    iput-object v1, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_abImage:[B

    .line 36
    iput-object p1, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_oImage:Lcom/glympse/platform/GImage;

    .line 37
    iput p2, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_nRotation:I

    .line 40
    iput-boolean v2, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_fCompleteOnMainThread:Z

    .line 43
    iput-boolean v2, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_fPost:Z

    .line 49
    invoke-static {}, Lcom/glympse/platform/Platform;->instance()Lcom/glympse/platform/Platform;

    move-result-object v0

    invoke-virtual {v0, p0}, Lcom/glympse/platform/Platform;->AddGlympseListener(Lcom/glympse/platform/common/GlympseListener;)V

    .line 50
    invoke-static {}, Lcom/glympse/platform/Platform;->instance()Lcom/glympse/platform/Platform;

    move-result-object v0

    iget-object v0, v0, Lcom/glympse/platform/Platform;->m_oServerPost:Lcom/glympse/platform/common/ServerPost;

    invoke-virtual {v0}, Lcom/glympse/platform/common/ServerPost;->PostNow()V

    .line 51
    return-void
.end method


# virtual methods
.method public AddRequestHeaders(Lcom/glympse/platform/GHttpConnection;)V
    .locals 3
    .parameter "oHttpConn"

    .prologue
    .line 75
    :try_start_0
    const-string v1, "User-Agent"

    iget-object v2, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_strAgent:Ljava/lang/String;

    invoke-virtual {p1, v1, v2}, Lcom/glympse/platform/GHttpConnection;->SetRequestProperty(Ljava/lang/String;Ljava/lang/String;)V

    .line 76
    const-string v1, "Content-Type"

    const-string v2, "multipart/form-data; boundary=---------------------------7d831e11c0b10"

    invoke-virtual {p1, v1, v2}, Lcom/glympse/platform/GHttpConnection;->SetRequestProperty(Ljava/lang/String;Ljava/lang/String;)V

    .line 77
    iget-object v1, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_strSession:Ljava/lang/String;

    invoke-static {v1}, Lcom/glympse/platform/common/Helpers;->IsEmpty(Ljava/lang/String;)Z

    move-result v1

    if-nez v1, :cond_0

    .line 79
    const-string v1, "GLYMPSE_Session"

    iget-object v2, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_strSession:Ljava/lang/String;

    invoke-virtual {p1, v1, v2}, Lcom/glympse/platform/GHttpConnection;->SetRequestProperty(Ljava/lang/String;Ljava/lang/String;)V

    .line 82
    :cond_0
    new-instance v1, Ljava/lang/StringBuilder;

    const-string v2, "UploadAvatarJob - Session:"

    invoke-direct {v1, v2}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    iget-object v2, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_strSession:Ljava/lang/String;

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    const-string v2, ", URL:"

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    iget-object v2, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_strUrl:Ljava/lang/String;

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    invoke-static {v1}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/String;)V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    .line 88
    :goto_0
    return-void

    .line 84
    :catch_0
    move-exception v1

    move-object v0, v1

    .line 86
    .local v0, e:Ljava/lang/Exception;
    invoke-static {v0}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/Throwable;)V

    goto :goto_0
.end method

.method public DoUpdate(I)V
    .locals 2
    .parameter "nUpdateFlags"

    .prologue
    .line 57
    and-int/lit8 v0, p1, 0x14

    if-eqz v0, :cond_0

    .line 59
    invoke-static {}, Lcom/glympse/platform/Platform;->instance()Lcom/glympse/platform/Platform;

    move-result-object v0

    invoke-virtual {v0, p0}, Lcom/glympse/platform/Platform;->RemoveGlympseListener(Lcom/glympse/platform/common/GlympseListener;)V

    .line 62
    invoke-static {}, Lcom/glympse/platform/Platform;->instance()Lcom/glympse/platform/Platform;

    move-result-object v0

    iget-object v0, v0, Lcom/glympse/platform/Platform;->m_oServerPost:Lcom/glympse/platform/common/ServerPost;

    iget-object v0, v0, Lcom/glympse/platform/common/ServerPost;->m_strSession:Ljava/lang/String;

    iput-object v0, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_strSession:Ljava/lang/String;

    .line 63
    new-instance v0, Ljava/lang/StringBuilder;

    invoke-static {}, Lcom/glympse/platform/Platform;->instance()Lcom/glympse/platform/Platform;

    move-result-object v1

    iget-object v1, v1, Lcom/glympse/platform/Platform;->m_oServerPost:Lcom/glympse/platform/common/ServerPost;

    invoke-virtual {v1}, Lcom/glympse/platform/common/ServerPost;->GetSessionUrl()Ljava/lang/String;

    move-result-object v1

    invoke-static {v1}, Ljava/lang/String;->valueOf(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v1

    invoke-direct {v0, v1}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    const-string v1, "UploadAvatar/"

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v0

    invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v0

    iput-object v0, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_strUrl:Ljava/lang/String;

    .line 65
    invoke-static {}, Lcom/glympse/platform/Platform;->instance()Lcom/glympse/platform/Platform;

    move-result-object v0

    iget-object v0, v0, Lcom/glympse/platform/Platform;->m_oJobQueue:Lcom/glympse/platform/common/JobQueue;

    invoke-virtual {v0, p0}, Lcom/glympse/platform/common/JobQueue;->AddJob(Lcom/glympse/platform/common/JobQueue$Job;)V

    .line 67
    :cond_0
    return-void
.end method

.method public GetPostSize()I
    .locals 8

    .prologue
    .line 96
    :try_start_0
    const-string v2, "-----------------------------7d831e11c0b10\r\nContent-Disposition: form-data; filename=\"filename.jpg\"\r\nContent-Type: image/pjpeg\r\n\r\n"

    .line 102
    .local v2, strBefore:Ljava/lang/String;
    const-string v1, "\r\n-----------------------------7d831e11c0b10--\r\n"

    .line 105
    .local v1, strAfter:Ljava/lang/String;
    const-string v3, "UTF-8"

    invoke-virtual {v2, v3}, Ljava/lang/String;->getBytes(Ljava/lang/String;)[B

    move-result-object v3

    iput-object v3, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_abBefore:[B

    .line 106
    const-string v3, "UTF-8"

    invoke-virtual {v1, v3}, Ljava/lang/String;->getBytes(Ljava/lang/String;)[B

    move-result-object v3

    iput-object v3, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_abAfter:[B

    .line 111
    iget-object v3, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_oImage:Lcom/glympse/platform/GImage;

    const/16 v4, 0x140

    const/16 v5, 0x140

    const/4 v6, 0x3

    iget v7, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_nRotation:I

    invoke-virtual {v3, v4, v5, v6, v7}, Lcom/glympse/platform/GImage;->GetScaledBitmap(IIII)Lcom/glympse/platform/GBitmap;

    move-result-object v3

    const/4 v4, 0x0

    const/16 v5, 0x50

    invoke-virtual {v3, v4, v5}, Lcom/glympse/platform/GBitmap;->GetBytes(II)[B

    move-result-object v3

    iput-object v3, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_abImage:[B
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    .line 119
    .end local v1           #strAfter:Ljava/lang/String;
    .end local v2           #strBefore:Ljava/lang/String;
    :goto_0
    iget-object v3, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_abBefore:[B

    array-length v3, v3

    iget-object v4, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_abImage:[B

    array-length v4, v4

    add-int/2addr v3, v4

    iget-object v4, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_abAfter:[B

    array-length v4, v4

    add-int/2addr v3, v4

    return v3

    .line 113
    :catch_0
    move-exception v3

    move-object v0, v3

    .line 115
    .local v0, e:Ljava/lang/Exception;
    invoke-static {v0}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/Throwable;)V

    goto :goto_0
.end method

.method public OnComplete(Lcom/glympse/platform/common/JobQueue;)V
    .locals 1
    .parameter "oJobQueue"

    .prologue
    .line 150
    iget-boolean v0, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_fSuccess:Z

    if-eqz v0, :cond_0

    .line 152
    invoke-static {}, Lcom/glympse/platform/Platform;->instance()Lcom/glympse/platform/Platform;

    move-result-object v0

    iget-object v0, v0, Lcom/glympse/platform/Platform;->m_oServerPost:Lcom/glympse/platform/common/ServerPost;

    invoke-virtual {v0}, Lcom/glympse/platform/common/ServerPost;->PostNow()V

    .line 154
    :cond_0
    return-void
.end method

.method public WritePostData(Ljava/io/OutputStream;)Z
    .locals 6
    .parameter "oHttpWrite"

    .prologue
    const/4 v5, 0x0

    const/4 v4, 0x0

    .line 128
    :try_start_0
    iget-object v1, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_abBefore:[B

    const/4 v2, 0x0

    iget-object v3, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_abBefore:[B

    array-length v3, v3

    invoke-virtual {p1, v1, v2, v3}, Ljava/io/OutputStream;->write([BII)V

    .line 129
    iget-object v1, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_abImage:[B

    const/4 v2, 0x0

    iget-object v3, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_abImage:[B

    array-length v3, v3

    invoke-virtual {p1, v1, v2, v3}, Ljava/io/OutputStream;->write([BII)V

    .line 130
    iget-object v1, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_abAfter:[B

    const/4 v2, 0x0

    iget-object v3, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_abAfter:[B

    array-length v3, v3

    invoke-virtual {p1, v1, v2, v3}, Ljava/io/OutputStream;->write([BII)V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    .line 138
    iput-object v5, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_abBefore:[B

    .line 139
    iput-object v5, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_abImage:[B

    .line 140
    iput-object v5, p0, Lcom/glympse/platform/common/UploadAvatarJob;->m_abAfter:[B

    .line 142
    const/4 v1, 0x1

    :goto_0
    return v1

    .line 132
    :catch_0
    move-exception v1

    move-object v0, v1

    .line 134
    .local v0, e:Ljava/lang/Exception;
    invoke-static {v0}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/Throwable;)V

    move v1, v4

    .line 135
    goto :goto_0
.end method
